package com.ushine.design.design.b_structural_type.g_proxy.b_example;

public class ProxySearch implements Searcher {
    private RealSerach realSerach = new RealSerach();
    private AccessValidator accessValidator;
    private Logger logger;

    //登录验证
    public boolean validate(String userId) {
        accessValidator = new AccessValidator();
        return accessValidator.validate(userId);
    }

    //日志记录
    public void log(String userId) {
        logger = new Logger();
        logger.log(userId);
    }

    //如果身份验证成功，则执行查询
    @Override
    public String doSearch(String userId, String keyword) {
        if (this.validate(userId)) {
            String result = realSerach.doSearch(userId, keyword);
            this.log(userId);
            return result;
        }
        return null;
    }

}
